<template>
  <div class="selft">
    <van-swipe class="my-swipe" :autoplay="3000" indicator-color="white">
      <van-swipe-item v-for="(item,index) in banner" :key="index">
          <img :src="item.picUrl" alt="">
      </van-swipe-item>
    </van-swipe>
    <div class="title">人气推荐<van-icon name="arrow" /></div>
    <ul class="people">
        <li v-for="(item,index) in goodsList" :key="index">
            <my-cart :itemObj="item" @click="$router.push(`/detail/${item.id}`)"></my-cart>
        </li>
    </ul>
  </div>
</template>

<script>
import { ref, reactive, toRefs } from "vue";
import api from "../../api/index";
import myCart from '../../components/myCart.vue';
export default {
  components: { myCart },
  setup() {
    const data = reactive({
      banner: [], // 轮播图的数据
      goodsList: [], // 人气推荐的数据
    });

    api.get("/banner/list").then((res) => {
      // 轮播图的请求
      data.banner = res.data;
    });

    api.get('/shop/goods/list').then(res => {
        data.goodsList = res.data.splice(9,4);
    })
    return {
      ...toRefs(data),
    };
  },
};
</script>
<style lang="scss" scoped>
.selft {
//   height: 100%;
  overflow: auto;
  .title{
    height: 50px;
    line-height: 50px;
    text-align: center;
    background: #fff;

  }
  .people{
    display: flex;
    padding: 0 5px;
    justify-content: space-between;
    flex-wrap: wrap;
    li {
      width: 49%;
    }
  }
}
.my-swipe{
  img{
    width: 100%;
  }
}

</style>